<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no" />
		<title>注册</title>
		<link rel="stylesheet" type="text/css" href="../css/aui.css" />
		<link rel="stylesheet" type="text/css" href="../css/reg.css" />
	</head>
	<body>
		<div class="aui-content aui-margin-b-15 fx-reg">
			<div style="padding: 0.5rem 0;">
				<img style="width: 80%;margin-left: 10%;" src="../image/zhuce/liandianzixun.png"/>
			</div>
			<ul class="aui-list aui-form-list" style="position: relative;"> 

				<li class="aui-list-item">
					<div class="aui-list-item-inner">
						<div class="aui-list-item-label-icon">
							<i class="aui-iconfont">
								<img src="../image/zhuce/phonereg.png" style="width: 1rem;height: 1rem;">
							</i>
						</div>
						<div class="aui-list-item-input">
							<input type="tel" id="username" value="" placeholder="请输入手机号码">
						</div>
					</div>
				</li>
				
				<li class="aui-list-item">
					<div class="aui-list-item-inner">
						<div class="aui-list-item-label-icon">
							<i class="aui-iconfont">
								<img src="../image/zhuce/messagereg.png" style="width: 2rem;height: 1rem;">
							</i>
						</div>
						<div class="aui-list-item-input">
							<input type="tel" id="code" placeholder="请输入短信验证码" value="">
						</div>
						<span class="aui-input-addon" style="margin-right: 1rem;">
							<div class="aui-btn" id="sendVerify" status="1" style="margin-right: 2rem;background: #FDA316;" onclick="getVerify()">
								获取验证码
							</div>
						</span>
					</div>
				</li>

				<li class="aui-list-item">
					<div class="aui-list-item-inner">
						<div class="aui-list-item-label-icon">
							<i class="aui-iconfont">
								<img src="../image/zhuce/passwordreg.png" style="width: 1rem;height: 1rem;">
							</i>
						</div>
						<div class="aui-list-item-input">
							<input type="password" id="password" placeholder="设置密码(6-12位字母或数字)" value="">
						</div>
					</div>
				</li>

				<!-- <li class="aui-list-item" style="position:absolute;top: 1000rem;">
					<div id="v5-submit" style="width: 16rem;" v5-config="{ name:'login-v5' , ssl:true,host:'yhwaow04i61vx1jw.verify5.com' ,token:'141a5f0208684fa4856ae38036be8434' }"></div>
				</li> -->

				<!-- <li class="aui-list-item" id="yqm">
					<div class="aui-list-item-inner">
						<div class="aui-list-item-label-icon">
							<i class="aui-iconfont aui-icon-like"></i>
						</div>
						<div class="aui-list-item-input">
							<input type="tel" placeholder="邀请码（可选）"  value="">
						</div>
					</div>
				</li> -->
				<li class="aui-list-item">
					<div class="aui-list-item-inner">
						<label style="margin:0 auto; font-size: 0.7rem;">
							<input class="aui-checkbox" type="checkbox" id="checkbox"  checked />
							我同意<a style=" font-size: 0.7rem;" href="javascript:;" tapmode onclick="_url({url:'about',id:'2',title:'用户协议和隐私条款'})">"用户协议和隐私条款"</a> </label>
					</div>
				</li>
			</ul>
			<div class="aui-btn-blocks aui-margin-15"">
				<div class="aui-btn aui-btn-block aui-btn-danger " id="tijiao" style="background: #FDA316 !important;height: 2rem !important;line-height: 2rem;">
					立即提交注册领取红包
				</div>
			</div>

			<div>
				<img style="width: 80%;margin-left: 10%;" src="../image/zhuce/bannerreg.png" alt="">
			</div>
		</div>
		<script type="text/javascript" src="../script/zepto.min.js"></script>
		<script type="text/javascript" src="../script/fastclick.js"></script>
		<script type="text/javascript" src="../script/api.js"></script>
		<script type="text/javascript" src="../script/ffxiang.js"></script>
		<script src="https://s.verify5.com/assets/latest/v5.js" type="text/javascript"></script>
		<script type="text/javascript">
			apiready = function() {
				// 监听夜间
			api.addEventListener({
			    name: 'yejian'
			}, function(ret, err) {
				if(ret){
					_yejians();
				}
			});
				var openid = api.pageParam['openid'];
				var type = api.pageParam['type'];
				if (openid && type) {
					$api.text($api.dom('#tijiao'), '绑  定');
				} else {
					openid = '';
					type = '';
				}
				FastClick.attach(document.body)
				$('#tijiao').click(function() {
					var username = $('#username').val();
					var password = $('#password').val();
					var code = $('#code').val();
					var yqm = $('#yqm input').val() ? $('#yqm input').val() : 0;
					if (!username) {
						_msg('手机号码不能空')
						return;
					}
					if (!_isMobile(username)) {
						_msg('请输入正确手机号码')
						return;
					}
					if (!password) {
						_msg('请设置新密码');
						return
					}
					if (!code) {
						_msg('手机验证码不能为空');
						return
					}
					var checkbox = $('#checkbox').is(':checked');
					if (checkbox == false) {
						_msg('请先同意服务条款')
						return false;
					}
					_loading();
					if (openid && type) {
						_ajax('api/user/reg', function(ret, err) {
							//	_msg('tokens:' + JSON.stringify(ret) + "\r\nerr:" + JSON.stringify(err))
							var tokens = ret.token;
							if (tokens) {
								_ajaxs('api/member/info', function(rets, errs) {
									//_msg('rets:' + JSON.stringify(rets) + "\r\nerrs:" + JSON.stringify(errs))
									if (rets.ret) {
										_loadingCloes();
										$api.setStorage('token', ret.ret);
										$api.setStorage('user', rets.ret);
										_msg('登录成功', function(retty) {
											if (retty) {
												_hone();
											}
										})
									} else {
										_loadingCloes();
										_msg(rets.err)
									}
								}, {
									token : tokens
								})
							} else {
								_loadingCloes();
								_msg(ret.err)
							}
						}, {
							username : username,
							password : password,
							code : code,
							type : type,
							token : openid,
							yaoqingma:yqm
						})
					} else {
						_ajax('api/user/reg', function(ret, err) {
							_loadingCloes();
							if (ret.ret) {
								_alert(ret.ret, function(ret) {
									_close()
								})
							} else {
								_msg(ret.err)
							}
						}, {
							username : username,
							password : password,
							code : code,
							yaoqingma:yqm
						})
					}
				})
			}
			var smsVerify
			function getVerify() {
				var mobileVal = $('#username').val();
				if (!mobileVal) {
					_msg('请输入手机号码')
					return false;
				} 
				if (!_isMobile(mobileVal)) {
					_msg('请输入正确手机号码')
					return;
				}
				// console.log('==========')
				_ajax('api/Icheck/getToken', function(ret, err) {
					// console.log(JSON.stringify(ret), '---------')
					let requestHost = ret.ret.host
					let requestToken = ret.ret.token
					// console.log(requestHost, requestToken, '9999999999')
					var v5=new com.strato.Verify5({
						ssl:true,
						host:requestHost,
						token:requestToken,
						// host:"yhwaow04i61vx1jw.verify5.com",
						trustLevel:5
					});
					v5.verify(function(result){
						let verifyId = result.verifyId
						if(result.success === true) {
							var status = $('#sendVerify').attr('status');
							if (status != 1) {
								return;
							}
							_loading();
							_ajax('api/index/code', function(ret, err) {
								_loadingCloes()
								if (ret) {
									if (ret.ret) {
										$("#sendVerify").html('<span id="GetVerify">120</span>S');
										times = 119;
										isinerval = setInterval("CountDown()", 1000);
										setTimeout(function() {
											_msg(ret.ret)
											$('#sendVerify').attr('status', '0');
										}, 500)
									} else {
										_msg(ret.err)
									}
								} else {
									_msg(ret)
								}
							}, {
								username : mobileVal,
								text : '注册',
								token : requestToken,
								vuid: verifyId
							})
						}
					});
				})
			}

			function CountDown() {
				if (times < 1) {
					var sendVerify = $('#sendVerify');
					$(sendVerify).attr('onclick', 'getVerify()');
					$(sendVerify).attr('status', '1');
					$(sendVerify).html('重新获取');
					clearInterval(isinerval);
					return;
				}
				var getVerify = $('#GetVerify');
				$(getVerify).html('' + times + '');
				times--;
			}

			// 验证手机号码
			function _isMobile(mobile) {
				if (mobile == "") {
					return false;
				} else {
					if (! /^0{0,1}(13[0-9]|15[0-9]|17[0-9]|18[0-9]|14[0-9])[0-9]{8}$/.test(mobile)) {
						return false;
					}
					return true;
				}
			}
		</script>
